package 注解;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static java.lang.Thread.sleep;

public class main {

    public static void main(String[] args) {

        ExecutorService executor = Executors.newFixedThreadPool(6);


        CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(()->{
            try {
                Thread.sleep(1000);
                System.out.println("1111111111111");
                return "111111111111";
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        CompletableFuture<String> cf2 = CompletableFuture.supplyAsync(()->{
            System.out.println("2222222222222");
            return "222222222222";
        });

        cf1.thenCombine(cf2,(result1,result2)->{
            System.out.println(result1+"---"+result2);
            return "3333333";
        }).thenAccept(result3 -> System.out.println(result3));

        executor.shutdown();
        try {
            executor.awaitTermination(Long.MAX_VALUE, java.util.concurrent.TimeUnit.NANOSECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
